#*-* utf-8 -*-
import numpy as np;
import scipy.sparse as sp;
import time
import threading
import os
from multiprocessing import Process
import profile
import utils
import heapq;
syn_dict = {};
def load_syn(syn):
    f = open(syn, 'r');
    for line in f:
        li = line.strip().split('\t');
        i = int(li[0]);
        j = int(li[1]);
        s = float(li[2]);
        if i != -1 and j != -1:
            if syn_dict.has_key(i):
                syn_dict[i].append((j,s));
            else:
                syn_dict[i] = [];
                syn_dict[i].append((j,s));
 
def score(x, y):
    s = x.dot(y.transpose());
    return s.todense()[0][0];

if __name__ == '__main__':
  Lx_1 = utils.load_sparse_csr('Ly_rp100_week.txt.npz');
  Lx_2  = utils.load_sparse_csr('Ly_rp100_t_week.txt.npz')
  print Lx_1.shape, Lx_2.shape;
  h = [(0,(0,0))] * 50;
  load_syn('LabeledData/documents_I');
  M1 = Lx_1.dot(Lx_1.transpose());
  M2 = Lx_2.dot(Lx_2.transpose());

  M = M2 - M1;

  h = []

  for i in syn_dict.keys():
    row = M[i].todense().getA1();
    for k, v in syn_dict[i]:
        h.append((row[k]*v, (i, k)));

  hh = heapq.nlargest(500, h);
  for s, pair in hh:
    print '%f,%d,%d' % (s, pair[0], pair[1]);


  
            
